/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.authorisation;

import apus.entity.User;
import apus.persistence.UserDAO;
import apus.services.ServiceLocator;

/**
 *
 * @author 21vek
 */
public class UserAuthorisationFactory {

    public static UserAuthorisation getAuthorizedUser(String login, int role) {
        
        UserAuthorisation authorisation = new UserAuthorisation();
        authorisation.setAutorised(true);
        authorisation.setLogin(login);
        
        UserDAO userDao = ServiceLocator.getService(UserDAO.class);
        User user = new User();
        user.setLogin(login);
        
        if (role == 1) {
            authorisation.setRole(UserAuthorisation.Role.ADMIN);
            authorisation.setUsername(login);
        }
        if (role == 2) {
            authorisation.setRole(UserAuthorisation.Role.CASHIER);
            authorisation.setUsername(login);
        }
        if (role == 3) {
            authorisation.setRole(UserAuthorisation.Role.USER);
            authorisation.setUsername(userDao.getSubscriberName(user));
        }
       

        return authorisation;
    }
}
